package com.sosky;

import java.util.Arrays;

/**
 * 17.08. 马戏团人塔
 * <p>
 * 有个马戏团正在设计叠罗汉的表演节目，一个人要站在另一人的肩膀上。出于实际和美观的考虑，在上面的人要比下面的人矮一点且轻一点。
 * 已知马戏团每个人的身高和体重，请编写代码计算叠罗汉最多能叠几个人。
 * <p>
 * 示例：
 * 输入：height = [65,70,56,75,60,68] weight = [100,150,90,190,95,110]
 * 输出：6
 * 解释：从上往下数，叠罗汉最多能叠 6 层：(56,90), (60,95), (65,100), (68,110), (70,150), (75,190)
 * <p>
 * 提示：
 * height.length == weight.length <= 10000
 */
public class Solution17_08 {
    public static void main(String[] args) {
//        System.out.println(bestSeqAtIndex(new int[]{65, 70, 56, 75, 60, 68}, new int[]{100, 150, 90, 190, 95, 110}));
        System.out.println(bestSeqAtIndex(new int[]{2868, 5485, 1356, 1306, 6017, 8941, 7535, 4941, 6331, 6181}, new int[]{5042, 3995, 7985, 1651, 5991, 7036, 9391, 428, 7561, 8594}));
    }

    public static int bestSeqAtIndex(int[] height, int[] weight) {
        int result = 1;
        for (int i = 0; i < height.length - 1; i++) {
            for (int j = i + 1; j < height.length; j++) {
                if (height[i] > height[j]) {
                    int x = height[i];
                    height[i] = height[j];
                    height[j] = x;
                    int y = weight[i];
                    weight[i] = weight[j];
                    weight[j] = y;
                }
            }
        }
        System.out.println(Arrays.toString(height));
        System.out.println(Arrays.toString(weight));
        int preHeight = height[0];
        int preWeight = weight[0];
        System.out.println(preHeight + " : " + preWeight);
        for (int i = 1; i < height.length; i++) {
            if (height[i] > preHeight && weight[i] > preWeight) {
                preHeight = height[i];
                preWeight = weight[i];
                System.out.println(preHeight + " : " + preWeight);
                result++;
            }
        }
        return result;
    }
}
